package com.example.demo.mapper;

import com.example.demo.entity.Score;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ScoreMapper {
    @Delete("delete from score where id=#{id} and term=#{term}")
    int delete(@Param("id") int id,@Param("term")String term);

    @Select("select * from score")
    List<Score> findAllScore();

    @Select("select * from score where id=#{id} group by term")
    List<Score> findScoreByIdGroupByTerm(int id);

    @Select("select * from score where id=#{id}")
    List<Score> findScoreByOne(int id);

    @Delete("delete from score where flag=#{flag}")
    int deleteScore(int flag);

    @Select("select * from score order by flag desc limit 1 ")
    Score selectLast();

    @Insert("insert into score(flag,id,name,major,classi,course,teachername,gredit,escore,ascore,fscore,term) values (#{flag},#{id},#{name},#{major},#{classi},#{course},#{teachername},#{gredit},#{escore},#{ascore},#{fscore},#{term})")
    int addScore(Score s);

    @Select("select * from score where flag=#{flag}")
    Score findScore(int flag);

    @Select("select * from score where id=#{id} and course=#{course}")
    Score findNeedScore(@Param("id")int id,@Param("course")String course);

    @Select("select * from score where term=#{term}")
    List<Score> findScoreByTerm(String term);

    @Select("select * from score where id=#{id} and term=#{term}")
    List<Score> findScoreByTermAndId(@Param("id")int id,@Param("term")String term);

    @Update("update score set ascore=#{ascore},fscore=#{fscore} where flag=#{flag}")
    int updateSco(@Param("flag")int flag,@Param("ascore")Float ascore,@Param("fscore")int fscore);

    @Insert("<script> insert into score "
            + "(id,name,major,classi,course,teachername,gredit,escore,ascore,fscore,term) "
            + "values "
            + "<foreach collection = 'list' item='record' separator=',' > "
            + " (#{record.id},#{record.name},#{record.major},#{record.classi},#{record.course},#{record.teachername},#{record.gredit},#{record.escore},#{record.ascore},#{record.fscore},#{record.term}) "
            + "</foreach>"
            + "</script>")
    int MultiAdd(List<Score> list);
}
